'''
目标函数:
    max z=x1^2+x2^2+3*x3^2+4*x4^2+2*x5^2-8*x1-2*x2-3*x3-x4-2*x5
约束条件:
    0<=xi<=99 (i=1,2,...,5)
    x1+x2+x3+x4+x5<=400
    x1+2*x2+2*x3+x4+6*x5<=800
    2*x1+x2+6*x3<=200
    x3+x4+5*x5<=200

如果暴力枚举的话需要计算10^10个点,太大,所以用蒙特卡罗法
'''
import random

for a in range(5):
    zmax = 0
    x11 = 0
    x12 = 0
    x13 = 0
    x14 = 0
    x15 = 0
    for i in range(0, 1000000):
        x1 = random.randint(0, 99)
        x2 = random.randint(0, 99)
        x3 = random.randint(0, 99)
        x4 = random.randint(0, 99)
        x5 = random.randint(0, 99)
        if x1 ** 2 + x2 ** 2 + 3 * x3 ** 2 + 4 * x4 ** 2 + 2 * x5 ** 2 - 8 * x1 - 2 * x2 - 3 * x3 - x4 - 2 * x5 < zmax or x1 + x2 + x3 + x4 + x5 > 400 or x1 + 2 * x2 + 2 * x3 + x4 + 6 * x5 > 800 or 2 * x1 + x2 + 6 * x3 > 200 or x3 + x4 + 5 * x5 > 200:
            continue
        zmax = x1 ** 2 + x2 ** 2 + 3 * x3 ** 2 + 4 * x4 ** 2 + 2 * x5 ** 2 - 8 * x1 - 2 * x2 - 3 * x3 - x4 - 2 * x5
        x11 = x1
        x12 = x2
        x13 = x3
        x14 = x4
        x15 = x5

    print(a,":")
    print("zmax:",zmax,"x1:", x11,"x2:", x12,"x3:", x13,"x4:", x14,"x5:", x15)

'''
结果如下：
0 :
zmax: 49986 x1: 42 x2: 95 x3: 2 x4: 99 x5: 18
1 :
zmax: 49417 x1: 15 x2: 99 x3: 5 x4: 99 x5: 17
2 :
zmax: 50566 x1: 47 x2: 98 x3: 1 x4: 99 x5: 11
3 :
zmax: 49921 x1: 46 x2: 94 x3: 0 x4: 99 x5: 15
4 :
zmax: 49776 x1: 33 x2: 98 x3: 3 x4: 99 x5: 15
'''

